// 管理所有与个人信息相关的接口
import http from '@/apis/utils/http'
import { type ApiRes, Page } from '@/apis/utils/common'

/**
 * 获取个人信息：返回数据的类型
 */
export interface MemberInfo {
  id: number
  username: string
  nickname: null | string
  realName: null | string
  gender: Gender
  avatar: string
  mobile: null | string
  // birthday: null | string
  /**
   * 省市区的名称：如山东省济南市里历下区
   */
  // fullAddress?: string
  // province?: null | string
  // city?: null | string
  // county?: null | string
  // profession: null | string
  remark: string
  servUserId?: number
  parentUserId?: number
}

/**
 * 性别，男、女、未知
 */
export enum Gender {
  未知 = 2,
  女 = 1,
  男 = 0
}

/**
 * 修改个人信息：请求参数类型
 */
export interface PutMemberProfileData {
  nickname?: null | string
  realName?: null | string
  gender?: Gender
  // /**
  //  * 生日 YYYY-MM-DD
  //  */
  // birthday?: null | string
  // fullAddress?: string
  // province?: null | string
  // city?: null | string
  // county?: null | string
  // profession?: null | string
}

/**
 * 获取个人信息
 * @returns
 */
export const useUserInfoApi = (): Promise<any> => {
  return http.get('/shipper/info', {
    headers: {
      ignore_refresh: true
    }
  })
}
export const userInfo2Api = (userId: number): Promise<MemberInfo> => {
  return http.get('/app/user/info2', {
    params: {
      userId
    }
  })
}

export const useAuthorityListApi = (): Promise<string[]> => {
  return http.get('/app/user/authority')
}
/**
 * 修改个人信息
 */
export const putMemberProfile = (data: PutMemberProfileData) =>
  http({
    url: '/app/user/upUserInfoAll',
    method: 'PUT',
    data
  })

export const upAvatarNickname = async (
  data: any,
  type: string
): Promise<string> =>
  await http.post('/app/user/upAvatarNickname', data, {
    headers: {
      'Content-Type': type
    }
  })

export const uploadAvatar = async (
  data: any,
  type: string
): Promise<string> => {
  return await http.post('/app/user/uploadAvatar', data, {
    headers: {
      'Content-Type': type
    }
  })
}

export const upUserMobile = async (data: string): Promise<string> =>
  await http.post('/app/user/upUserMobile', data)

export const getKidsList = (params: any): Promise<Page<MemberInfo>> =>
  http.get('/app/user/kidslist', { params })

export const editRemarkInfoApi = async (
  userId: number,
  remark: string
): Promise<string> => await http.put('/app/user/editRemark', { userId, remark })

export const bpSendCode = (mobile: string): Promise<string> => {
  return http.post('/app/user/bpSendcode?mobile=' + mobile)
}
export const bindParentApi = async (
  mobile: string,
  code: string
): Promise<string> =>
  await http.post(`/app/user/bindParent?mobile=${mobile}&code=${code}`)
